using UnityEngine;
using UnityEngine.UI;

namespace VoxelGame.Utils
{
	public class HUDFPS : MonoBehaviour
	{
		public float updateInterval = 0.5f;

		private float _accum;

		private int _frames;

		private float _timeleft;

		[SerializeField]
		private Text _fpsCounter;

		private void Start()
		{
			_timeleft = updateInterval;
		}

		private void Update()
		{
			_timeleft -= Time.deltaTime;
			_accum += Time.timeScale / Time.deltaTime;
			_frames++;
			if ((double)_timeleft <= 0.0)
			{
				float num = _accum / (float)_frames;
				string text = $"{num:F2} FPS";
				_fpsCounter.text = text;
				_timeleft = updateInterval;
				_accum = 0f;
				_frames = 0;
			}
		}
	}
}
